<?php
class YWSMessenger {
	public static $_MESSAGE = "YWS_MSG_TXT";
    public static $_TYPE = "NOTICE";
    public static $_TYPECOOKIE = "YWS_MSG_TYPE";
    public static $_ENABLER = "YWS_MSG_ENABLER";
    
    public static function Displayable()
    {
        // Initialize cookie
        if (!isset($_SESSION[YWSMessenger::$_MESSAGE])) 
            $_SESSION[YWSMessenger::$_MESSAGE] = null;
        if (!isset($_SESSION[YWSMessenger::$_TYPECOOKIE])) 
            $_SESSION[YWSMessenger::$_TYPECOOKIE] = null;
        if (!isset($_SESSION[YWSMessenger::$_ENABLER])) 
            $_SESSION[YWSMessenger::$_ENABLER] = 0;
        
        if ($_SESSION[YWSMessenger::$_ENABLER] == 0) return false;
        else return true;
    }
    
    public static function StatusWarning($msg) {
            return "
            <script>
                showWarningToast('".$msg."');
            </script>
            ";
	}
	
	public static function StatusSuccess($msg) {
            return "
            <script>
                showWarningToast('".$msg."');
            </script>
            ";
	}
	
	public static function StatusError($msg) {
            return "
            <script>
                showWarningToast('".$msg."');
            </script>
            ";
	}
	
	public static function StatusNotice($msg) {
            return "
            <script>
                showWarningToast('".$msg."');
            </script>
            ";
	}
	
	public static function SendMesssage($msg, $type = null) 
    {
        $_SESSION[YWSMessenger::$_ENABLER] = 1;
        $_SESSION[YWSMessenger::$_MESSAGE] = $msg;
        $_SESSION[YWSMessenger::$_TYPECOOKIE] = $type;
	}
    
    public static function DisplayMessage()
    {
        $msg = $_SESSION[YWSMessenger::$_MESSAGE];
        $type = $_SESSION[YWSMessenger::$_TYPECOOKIE];
        $type = ($type == null) ? "WARNING" : $type;
        switch($type) {
                case "WARNING":
                        return YWSMessenger::StatusWarning($msg);
                        break;
                case "SUCCESS":
                        return YWSMessenger::StatusSuccess($msg);
                        break;
                case "ERROR":
                        return YWSMessenger::StatusError($msg);
                        break;
                case "NOTICE":
                        return YWSMessenger::StatusNotice($msg);
                        break;
                default:
                        return YWSMessenger::StatusWarning($msg);
                        break;
        }
        //$_SESSION[YWSMessenger::$_ENABLER] = 0;
    }
}
?>
        